<?php

use console\db\Migration;

/**
 * 地点信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m150104_091356_t_region extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 区域地点信息表
         * @table `region`
         */
        $this->tableBuilder([
            'name' => 'region',
            'comment' => '区域地点信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'province' => $this->string(50)->notNull()->comment('省份'),
                'city' => $this->string(50)->notNull()->comment('市'),
                'district' => $this->string(50)->defaultValue('')->comment('地区'),
                'address_detail' => $this->string(255)->notNull()->comment('详细地址'),
                'area_code' => $this->char(6)->defaultValue('')->comment('地区码'),
                'postal_code' => $this->char(6)->defaultValue('')->comment('邮编'),
                'gis' => $this->geometry()->comment('空间位置信息'),
                'geohash' => $this->geometryHash('GIS'),
                'model' => $this->char(20)->defaultValue('')->comment('应用模型'),
                'model_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('应用模型ID'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%region}}');
    }

}
